package com.briup;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class Insert {
  public static void main(String[] args) {
    String resource = "mybatis-config.xml";
      SqlSession sqlSession = null;
      Student student = new Student(null, "dddd", "男", "1221");
      try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
          SqlSessionFactory build = new SqlSessionFactoryBuilder().build(inputStream);
          sqlSession = build.openSession(true);
          StuMapper mapper = sqlSession.getMapper(StuMapper.class);
          int insert = mapper.insert(student);
      System.out.println(student.getId());
      System.out.println(insert);
      }catch (Exception e){
          e.printStackTrace();
      }finally{
          sqlSession.close();
      }
  }
}
